append()函数使用报错解决:AttributeError: 'NoneType' object has no attribute 'append' 您所在的位置:网站首页 python str object has no attribute append append()函数使用报错解决:AttributeError: 'NoneType' object has no attribute 'append'

append()函数使用报错解决:AttributeError: 'NoneType' object has no attribute 'append'

2024-06-25 14:29| 来源: 网络整理| 查看: 265

问题描述

Python代码中使用append()函数后报错: AttributeError: ‘NoneType’ object has no attribute ‘append’ 代码:

L = L.append('a') 解决方法

将“L = L.append(‘a’)”改为L.append(‘a’)后问题解决

原因解释

append会修改L本身,并且返回None。不能把返回值再赋值给L

append()函数用法介绍

作用:在列表末尾添加新的对象 语法:list.append(obj) 参数:obj:添加至列表末尾的对象 返回值:该方法无返回值,会修改原来的列表 例子:

L = ['A','B','C'] L.append('D') print L

输出:[‘A’, ‘B’, ‘C’, ‘D’]



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有